package cn.iocoder.yudao.module.asasc.dal.mysql.campaign;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.asasc.controller.admin.campaign.vo.CampaignGrandTotalsPageReqVO;
import cn.iocoder.yudao.module.asasc.dal.dataobject.campaign.CampaignGrandTotalsDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 广告数据汇总 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface CampaignGrandTotalsMapper extends BaseMapperX<CampaignGrandTotalsDO> {

    default PageResult<CampaignGrandTotalsDO> selectPage(CampaignGrandTotalsPageReqVO reqVO) {
        List<Long> adamIds = reqVO.getAdamIds() != null ? Stream.of(reqVO.getAdamIds()).collect(Collectors.toList()) : null;

        return selectPage(reqVO, new LambdaQueryWrapperX<CampaignGrandTotalsDO>()
                .betweenIfPresent(CampaignGrandTotalsDO::getDate, reqVO.getDate())
                .betweenIfPresent(CampaignGrandTotalsDO::getCreateTime, reqVO.getCreateTime())
                .inIfPresent(CampaignGrandTotalsDO::getAdamId, adamIds)
                .eqIfPresent(CampaignGrandTotalsDO::getOrgId, reqVO.getOrgId())
                .orderByDesc(CampaignGrandTotalsDO::getDate));
    }

    Integer updateGrandTotalsByDateAndAdamId(CampaignGrandTotalsDO updateObj);
}